from docutils import nodes
from docutils.parsers.rst import roles

def annotate_role(name, rawtext, text, lineno, inliner, options={}, content=[]):
    """Custom role to wrap text in [ ] and make it superscript."""

    sup_node = nodes.superscript()  # Create a superscript node
    sup_node += nodes.Text(f"[{text}]")  # Add the annotation text inside

    sup_node['classes'].append('annotate')  # Apply the CSS class for styling
    return [sup_node], []

def setup(app):
    """Sphinx extension setup function."""

    roles.register_local_role("annotate", annotate_role)
    return {"version": "0.1", "parallel_read_safe": True, "parallel_write_safe": True}
